﻿using System;
using System.Collections.Generic;
using System.Data;
using POS.BusinessEntities;

namespace POS.DataObjects
{
    public class DOArticulo: DOBase
    {
        #region Declarations

        private const string getListSP = "ArticuloGetList";
        //private const string saveSP = "ArticuloSave";
        
        //private const string columnaCodigo = "id";
        //private const string columnaNombre = "nombre";
        //private const string columnaPrecio = "porcentaje";
        //private const string columnaExistencia = "existencia";
        //private const string columnaPorSurtir = "porSurtir";
        //private const string columnaPorRecibir = "porRecibir";
        //private const string columnaDisponible = "disponible";

        #endregion

        #region Methods: Public

        public virtual IList<BEArticuloBusqueda> GetList(int empresaId, string filter, SearchField searchField)
        {
            var result = new List<BEArticuloBusqueda>();

            var command = Db.GetStoredProcCommand(getListSP);
            Db.AddInParameter(command, "@empresaId", DbType.Int32, empresaId);
            if (searchField == SearchField.Name)
                Db.AddInParameter(command, "@filtroNombre", DbType.String, filter);
            else
                Db.AddInParameter(command, "@filtroCodigo", DbType.String, filter);

            var data = Db.ExecuteDataSet(command);

            if (data.Tables.Count == 1)
            {
                foreach (DataRow row in data.Tables[0].Rows)
                    result.Add(CreateEntityFromDataRow<BEArticuloBusqueda>(row));
            }
            return result;
        }

        //public virtual void Save(BEImpuesto entity, int empresaId, string user)
        //{
        //    var command = Db.GetStoredProcCommand(saveSP);
        //    Db.AddInParameter(command, "@id", DbType.Int32, entity.Id);
        //    Db.AddInParameter(command, "@name", DbType.String, entity.Nombre);
        //    Db.AddInParameter(command, "@percentage", DbType.Decimal, entity.Porcentaje);
        //    Db.AddInParameter(command, "@companyId", DbType.Int32, empresaId);
        //    Db.AddInParameter(command, "@user", DbType.String, user);
        //    Db.ExecuteNonQuery(command);
        //}

        #endregion
        
    }
}
